import java.util.*;
public class Solution {

    public ListNode EntryNodeOfLoop(ListNode pHead) {

        Set<ListNode> set=new HashSet<>();
        ListNode cur=pHead;
        while(cur!=null){

            if(!set.add(cur)){
                return cur;
            }
            cur=cur.next;
        }

        return null;
    }
}
